<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;

class GiftPearlLibrary extends BaseModel
{
    protected $table = 'gift_pearl_library';
    public $timestamps = false;
    protected $fillable = ['name', 'image', 'animate_resource','price','gift_sort'];
    private $fields = ['gift_id','name', 'image', 'animate_resource','price','gift_sort','is_show','animate_resource_md5'];
    protected $attributes = [
        'is_show' => 1,
        'gift_sort' => 0
    ];
    protected $primaryKey = 'gift_id';

    public function getList(Request $request){
        $page = $request->get('page', 0);
        $limit = $request->get('limit', 10);
        $query = new GiftPearlLibrary();
        // todo 搜索
        return $query->orderBy('gift_id','desc')
            ->paginate($limit, $this->fields, 'page', $page);
    }

    public function getGiftByGiftName(string $name){
        return self::where('name','LIKE',"{$name}%")->get();
    }


    /*
        * 添加
        * */
    public function createData($data)
    {
        return curl_request(getKkaudioApiUrl() . '/inner/gift_pearl/create', $data, 'json', 'POST');
    }

    /*
         * 更新
         * */
    public function updateData($data)
    {
        return curl_request(getKkaudioApiUrl() . '/inner/gift_pearl/update', $data, 'json', 'POST');
    }


    /*
        * 删除
        * */
    public function removeData($data)
    {
        return curl_request(getKkaudioApiUrl() . '/inner/gift_pearl/remove', $data, 'urlencoded', 'GET');
    }

}
